package net.zjitc.dao.Admin.impl;

import net.zjitc.damain.Admin.Admin;
import net.zjitc.dao.Admin.AdminDao;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.springframework.stereotype.Repository;

import javax.annotation.Resource;

/**
 * Created by Administrator on 2017/3/6.
 */
@Repository
public class AdminDaoImpl implements AdminDao {
    @Resource
    private SessionFactory sessionFactory;

    @Override
    public Admin findByAdminnamePassword(String username, String password) {

        Session session = sessionFactory.openSession();
        Transaction transaction = session.beginTransaction();
        Admin admin = (Admin) session.createQuery(
                "from Admin a where a.username = ? and a.password = ?")
                .setParameter(0,username)
                .setParameter(1,password)
                .uniqueResult();
        transaction.commit();
        session.close();
        return admin;
    }
}
